/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DataAccessObject;

import EntityObject.tblConDauEO;
import java.sql.CallableStatement;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author minh
 */
public class tblConDauDAO {
   
    public static boolean ConDau_Insert(tblConDauEO _tblConDauEO) throws SQLException{
        try {
            String sql="{call tblConDau_Insert(?,?,?,?,?,?,?,?,?)}";
            CallableStatement cstmt=Connection.conn().prepareCall(sql);
            cstmt.setString(1, _tblConDauEO.getsTenCD());
            cstmt.setString(2, _tblConDauEO.getsTenHuy());
            cstmt.setString(3, _tblConDauEO.getsNoiSinh());
            cstmt.setString(4, _tblConDauEO.getsNoiOHienTai());
            cstmt.setString(5, _tblConDauEO.getsNgaySinh());
            cstmt.setString(6, _tblConDauEO.getsNgayMat());
            cstmt.setString(7, _tblConDauEO.getsNoiAnTang());
            cstmt.setInt(8, _tblConDauEO.getiDoiThu());
            cstmt.setString(9, _tblConDauEO.getsGhiChu());
            
            cstmt.execute();
            return true;
        }
        catch (SQLException e) {
            System.out.println(e);
            return false;
        }
        finally{Connection.conn().close();}
    }
    
    public static boolean ConDau_Update(tblConDauEO _tblConDauEO) throws SQLException{
        try {
            
            String sql="{call tblConDau_Update(?,?,?,?,?,?,?,?,?,?)}";
            CallableStatement cstmt=Connection.conn().prepareCall(sql);
            cstmt.setInt(1, _tblConDauEO.getPK_iMaCD());
            cstmt.setString(2, _tblConDauEO.getsTenCD());
            cstmt.setString(3, _tblConDauEO.getsTenHuy());
            cstmt.setString(4, _tblConDauEO.getsNoiSinh());
            cstmt.setString(5, _tblConDauEO.getsNoiOHienTai());
            cstmt.setString(6, _tblConDauEO.getsNgaySinh());
            cstmt.setString(7, _tblConDauEO.getsNgayMat());
            cstmt.setString(8, _tblConDauEO.getsNoiAnTang());
            cstmt.setInt(9, _tblConDauEO.getiDoiThu());
            cstmt.setString(10, _tblConDauEO.getsGhiChu());
            
            cstmt.execute();
            return true;
        }
        catch (SQLException e) {
            System.out.println(e);
            return false;
        }
        finally{Connection.conn().close();}
    }
    
    public static boolean ConDau_Delete(tblConDauEO _tblConDauEO) throws SQLException{
        try {
            String sql="{call tblConDau_Delete(?)}";
            CallableStatement cstmt=Connection.conn().prepareCall(sql);
            cstmt.setInt(1, _tblConDauEO.getPK_iMaCD());
            cstmt.execute();
            return true;
        }
        catch (SQLException e) {
            System.out.println(e);
            return false;
        }
        finally{Connection.conn().close();}
    }
    
    public static ResultSet ConDau_SelectList(tblConDauEO _tblConDauEO) throws SQLException{
        ResultSet rs =null;
        try {
            String sql="{call tblConDau_SelectList()}";
            CallableStatement cstmt=Connection.conn().prepareCall(sql);
//            cstmt.setString(1, dungcu.getMaDungCu());
            rs=cstmt.executeQuery();
            return rs;
        }
        catch (SQLException e) {
            System.out.println(e);
            return rs;
        }
        finally{Connection.conn().close();}
    }
    
    public static ResultSet ConDau_SelectItem(tblConDauEO _tblConDauEO) throws SQLException{
        ResultSet rs =null;
        try {
            String sql="{call tblConDau_SelectItem(?)}";
            CallableStatement cstmt=Connection.conn().prepareCall(sql);
            cstmt.setInt(1, _tblConDauEO.getPK_iMaCD());
            rs=cstmt.executeQuery();
            return rs;
        }
        catch (SQLException e) {
            System.out.println(e);
            return rs;
        }
        finally{Connection.conn().close();}
    }
}
